import { EChartsOption } from 'echarts'
import * as echarts from 'echarts/core'

export const seriesData = [
  { value: 0, name: '华东地区' },
  { value: 0, name: '华中地区' },
  { value: 0, name: '华南地区' },
  { value: 0, name: '华北地区' },
  { value: 0, name: '西北地区' },
  { value: 0, name: '西南地区' },
  { value: 0, name: '东北地区' }
]

const dealLegend=(name)=>{
  console.log()
  if (seriesData.length) {
    const item = seriesData.filter((item) => item.name === name)[0]
    return `${name}\n ${item.value}台`
  }
}

// 区域分布统计
export const pieOptions: EChartsOption = {
  title: {
    text: '总数统计',
    subtext: '0',
    left: '24%',
    top: '38%',
    textAlign: 'center',
    textStyle: {
      color: '#A8CAEA',
      fontWeight: 'normal',
      fontSize: 15,
      align: 'center'
    },
    subtextStyle: {
      align: 'center',
      color: '#DCEAF8',
      fontWeight: 'normal',
      fontSize: 20
    }
  },
  color: ['#549BF1', '#B4C9EF', '#5A70BC', '#AA8A6E', '#BCBF5C', '#67D470'],
  tooltip: {
    trigger: 'item'
  },

  series: [
    {
      name: '机场总数',
      type: 'pie',
      radius: ['70%', '80%'],
      center: ['25%', '50%'],
      minAngle: 10,
      avoidLabelOverlap: false,
      padAngle: 5,
      itemStyle: {},
      label: {
        show: false
      },

      labelLine: {
        show: false
      },
      data: seriesData,
      
    },
    {
      name: '背景',
      type: 'pie',
      radius: ['50%', '60%'],
      center: ['25%', '50%'],
      avoidLabelOverlap: false,
      tooltip: {
        show: false // 直接禁用 tooltip
      },
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 1,
              color: '#2F476E'
            }
          ]),
          label: {
            show: false
          },
          labelLine: {
            show: false
          }
        }
      },
      label: {
        show: false
      },

      labelLine: {
        show: false
      },
      data: [0]
    }
  ],
  legend: {
    top: 'middle',
    left: '55%',
    itemGap: 0,
    itemWidth: 8,
    itemHeight: 6,
    textStyle: {
      color: '#fff',
      lineHeight: 16,
      fontSize: 12
    },
    formatter: dealLegend,
    // formatter: (name) => {
    //   if (seriesData.length) {
    //     const item = seriesData.filter((item) => item.name === name)[0]

    //     return `${name}\n ${item.value}台`
    //   }
    // }
  }

}

const colorList = {
  first: ['#F179C4', '#26AEFB', '#CDAD92', '#ED65BA', '#989FBB', '#E86A6A', '#6718CF'],
  second: ['#E33AA3', '#056FAB', '#FFAA62', '#E33AA3', '#28B1FF', '#FFAA62', '#F47384']
}
// 各领域数据统计
export const domainOptions: EChartsOption = {
  legend: {
    // 配置图例
    data: ['飞行架次', '飞行里程'],
    textStyle: {
      color: '#E9F0FF',
      fontSize: 12 // 图例字体大小
    },
    itemWidth: 14,
    itemHeight: 6,
    top: 6, // 图例的位置
    right: 10
  },
  grid: [
    {
      // 设置边距
      left: 30,
      bottom: 30,
      top: 50, // 增大 top 的值以使图表内容向下移动
      right: 30
    }
  ],
  yAxis: [
    {
      // Y轴配置
      type: 'value',
      position: 'left',
      splitLine: {
        lineStyle: {
          color: ['#155DAE'],
          type: 'dashed'
        }
      },
      axisLabel: {
        // Y轴文字
        color: '#E9F0FF',
        fontSize: 12
      }
    },
    {
      type: 'value',
      name: '',
      position: 'right',
      axisLabel: {
        formatter: '{value}',
        color: '#E9F0FF',
        fontSize: 12
      },
      splitLine: {
        show: false
      }
    }
  ],
  xAxis: {
    // X轴配置
    data: [],
    show: true,
    axisLabel: {
      color: '#E9F0FF',
      fontSize: 12,
      interval: 0,
      padding: [5, 0, 0, 0]
    }
  },
  series: [
    {
      name: '飞行架次',
      type: 'pictorialBar',
      symbol: 'roundRect',
      barWidth: '11%',
      barMaxWidth: '20%',
      symbolMargin: '3',
      animationDelay: (dataIndex, params: any) => {
        return params.index * 50
      },
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
            { offset: 0, color: '#0AEFFF' },
            { offset: 1, color: '#0CA0FE' }
          ])
        }
        // normal: {
        //   color: (params) => {
        //     const colors = ['#0AEFFF', '#26AEFB', '#CDAD92', '#ED65BA'];
        //     return colors[params.dataIndex % colors.length];
        //   }
        // }
      },
      z: 1,
      symbolRepeat: true,
      symbolBoundingData: 400,
      symbolSize: [15, 6],
      data: [],
      animationEasing: 'elasticOut'
    },
    {
      name: '飞行里程',
      type: 'line',
      label: {
        normal: {
          show: true,
          position: 'top'
        }
      },
      itemStyle: {
        color: '#E3BB67'
      },
      lineStyle: {
        normal: {
          width: 3,
          color: '#E3BB67',
          shadowColor: 'rgba(0,0,0,0.4)',
          shadowBlur: 10,
          shadowOffsetY: 10
        }
      },
      symbol: 'circle',
      symbolSize: 10,
      yAxisIndex: 1,
      data: [235, 175, 280, 200],
      // data: [0,0,0,0,0],
      label: {
        show: true,
        position: 'top',
        color: '#ffffff'
      }
    }
  ]
}
